//
//  MotionBlurScene.h
//  Ray Tracer
//
//  Created by Kaila, Ashish on 4/1/13.
//  Copyright (c) 2013 Kaila, Ashish. All rights reserved.
//

#ifndef Ray_Tracer_MotionBlurScene_h
#define Ray_Tracer_MotionBlurScene_h

void renderMotionBlurScene(Raytracer& raytracer,
                           int width,
                           int height,
                           bool enableSpecular)
{
    // Camera parameters.
	Point3D eye(0, 0, 20);
	Vector3D view(0, 0, -1);
	Vector3D up(0, 1, 0);
	double fov = 20;
    
	// Defines a material for shading.
	SolidMaterial red( Colour(0.8, 0, 0), Colour(0.8, 0, 0),
                      Colour(0.8, 0.8, 0.8),
                      10,
                      0.5,
                      0.3,
                      0.166);
    
	SolidMaterial green( Colour(0, 0.8, 0), Colour(0, 0.8, 0),
                        Colour(0.8, 0.8, 0.8),
                        10,
                        0.5,
                        0.3,
                        0.166);
    
    SolidMaterial blue( Colour(0, 0, 0.8), Colour(0, 0, 0.8),
                       Colour(0.8, 0.8, 0.8),
                       10,
                       0.5,
                       0.3,
                       0.166);
    
	SolidMaterial yellow( Colour(0.8, 0.8, 0), Colour(0.8, 0.8, 0),
                         Colour(0.8, 0.8, 0.8),
                         10,
                         0.5,
                         1,
                         0.166);
    /*
     SolidMaterial yellow(Colour(0.25, 0.25, 0.25), Colour(0.4, 0.4, 0.4),
     Colour(0.774597, 0.774597, 0.774597),
     76.8,
     1,
     1,
     0.166);
     */
    SolidMaterial back( Colour(0.85098039215686, 0.4, 0.43529411764706), Colour(0.85098039215686, 0.4, 0.43529411764706),
                       Colour(0.5, 0.5, 0.5),
                       10,
                       0.5,
                       0.3,
                       0.166);
    
    SolidMaterial jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                       Colour(0.316228, 0.316228, 0.316228),
                       12.8,
                       0.5,
                       0.001,
                       1.66);
    
	// Defines a point light source.
	raytracer.addLightSource( new PointLight(Point3D(0, 0, 20),
                                             Colour(0.9, 0.9, 0.9) ),
                             enableSpecular);
    
	// Add a unit square into the scene with material mat.
    SceneDagNode* backSphere = raytracer.addObject( new UnitSphere(&back));
	SceneDagNode* redSphere = raytracer.addObject( new UnitSphere(&red));
	SceneDagNode* greenSphere = raytracer.addObject( new UnitSphere(&green));
	SceneDagNode* blueSphere = raytracer.addObject( new UnitSphere(&blue));
    SceneDagNode* yellowSphere = raytracer.addObject( new UnitSphere(&yellow));
    SceneDagNode* plane = raytracer.addObject( new UnitSquare(&jade));
    
    
	// Apply some transformations to the unit square.
	double scale[3] = { 1.5, 1.5, 1.5 };
    
    double spacing = 1.05;
    
    SceneObject* redSphereObj = redSphere->obj;
    redSphereObj->scale(Point3D(0, 0, 0), scale);
	redSphereObj->translate(Vector3D(-spacing, spacing, -5));
    
    SceneObject* greenSphereObj = greenSphere->obj;
    greenSphereObj->scale(Point3D(0, 0, 0), scale);
    greenSphereObj->translate(Vector3D(spacing, spacing, -5));
    
    SceneObject* blueSphereObj = blueSphere->obj;
    blueSphereObj->scale(Point3D(0, 0, 0), scale);
    blueSphereObj->translate(Vector3D(-spacing, -spacing, -5));

    SceneObject* yellowSphereObj = yellowSphere->obj;
    yellowSphereObj->scale(Point3D(0, 0, 0), scale);
    yellowSphereObj->translate(Vector3D(spacing, -spacing, -5));
    
    SceneObject* backSphereObj = backSphere->obj;
    backSphereObj->scale(Point3D(0, 0, 0), scale);
    backSphereObj->translate(Vector3D(0, 0, -8));
    
    double factor2[3] = { 16.0, 16.0, 16.0 };
    SceneObject* planeObj = plane->obj;
    planeObj->translate(Vector3D(0, 0, -10));
	planeObj->scale(Point3D(0, 0, 0), factor2);
    
    
    double distance = 0.5;
    MotionBlur motionBlur(blueSphere, Vector3D(-distance, -distance, 0));
    raytracer.setMotionBlur(&motionBlur);
    
	// Render the scene, feel free to make the image smaller for
	// testing purposes.
	raytracer.render(width, height, eye, view, up, fov, "motionblur1.bmp");
	
	// Render it from a different point of view.
    Point3D eye2(4, 2, 1);
	Vector3D view2(-4, -2, -6);
    
	raytracer.render(width, height, eye2, view2, up, fov, "motionblur2.bmp");
}

#endif
